package org.itboys.mobile.controller.small;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.service.mongo.weixin.SundayValicodedateService;
import org.itboys.mobile.service.mongo.weixin.SundayWeiXinYuyueService;
import org.itboys.mobile.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Auther: 罗尧坤
 * Date: 2018/7/17
 * Description: 集楼_楼卡_快速预约_小程序_接口
 */

@Controller
@RequestMapping("/sunday/small/yuyue")
@Api(value = "yuyue",description = "楼盘快速预约: 验证码在发送验证码后得到")
public class SundaySmallYuyueController extends BaseController {
    @Autowired
    private SundayWeiXinYuyueService yuyueService;


    /**
     * 保存用户预约表单
     * @param request
     * @param response
     * @param productId
     * @param memberId
     * @param phone
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "【小程序】快速预约接口")
    public void sava(HttpServletRequest request,
                     HttpServletResponse response,
                     @ApiParam(required=true, name="productId", value="预约楼盘id")
                     @RequestParam(value="productId",required = true)
                                 Long productId,
                     @ApiParam(required=true, name="memberId", value="预约用户id")
                     @RequestParam(value="memberId",required = true)
                                 Long memberId,
                     @ApiParam(required=true, name="phone", value="预约用户电话")
                     @RequestParam(value="phone",required = true)
                                 String phone,
                     @ApiParam(required=true, name="yzm", value="验证码")
                     @RequestParam(value="yzm",required = true)
                                 String yzm

    ){
        try{
            yuyueService.saveYuyue(productId,memberId,phone,yzm);
            ResponseMessage.success();
        }catch (Exception e){
            String msg = CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code= CommonConstants.TOKEN_CODE;
                msg= CommonConstants.TOKENMSG;
            }else{
                logger.error("/sunday/small/yuyue/save----e="+e.getMessage());
            }
            e.printStackTrace();
            ResponseMessage.error(code,msg);
        }
    }

}
